﻿/// <reference path="jquery-1.4.4-vsdoc.js" />

// Default configuration
$.mvc =
{
    name: "jquery.mvc", scriptfolder: "javascript", templatefolder: "template", controller: "home"
};

/// <summary>This returns the given loaded javascript file path</summary>
$.mvc.script = function (filename, folder)
{
    if (folder)
        return String.format("/views/{0}/{1}/{2}", $.mvc.controllername(), folder, filename);
    else
        return String.format("/views/{0}/{1}/{2}", $.mvc.controllername(), $.mvc.scriptfolder, filename);
}

/// <summary>This returns the given loaded template file path</summary>
$.mvc.template = function (filename, controller)
{
    if (controller)
        return String.format("/views/{0}/{1}/{2}", controller, $.mvc.templatefolder, filename);
    else
        return String.format("/views/{0}/{1}/{2}", $.mvc.controllername(), $.mvc.templatefolder, filename);
}

/// <summary>This returns the given loaded action file path</summary>
$.mvc.action = function (action, controller)
{
    if (controller)
        return String.format("/{0}/{1}", controller, action);
    else
        return String.format("/{0}/{1}", $.mvc.controller(), action);
}

/// <summary>This returns controller name</summary>
$.mvc.controllername = function ()
{
    var _controller = $.mvc.controller, controllerregex = /(?!^\/)[^\/]+/;

    if (controllerregex.test(window.location.pathname))
        _controller = controllerregex.exec(window.location.pathname)[0];

    return _controller;
}

/// <summary>This returns action name</summary>
$.mvc.actionname = function ()
{
    var _action = $.mvc.action, actionregex = /^\/[^\/]+\/?([^\/]+)/;

    if (actionregex.test(window.location.pathname))
        _action = actionregex.exec(window.location.pathname)[1];

    return _action;
}